<template>
    <span>
      {{ text }} 
    </span>
</template>
<script>
import quickTool from '@/assets/js/quick/quickTool.js'
import {codeProvider} from '@/assets/js/quick/provider.js'
export default {
  name: 'bms-table-text',
  mixins: [quickTool],
  props:{
    value : {type: null ,default:''},
    codeType : {type:String ,default:''},
    condition : {type:Object,default:()=>{}},
  },
  data(){
    return {
      text: ""
    }
  },
  methods : {
    async initData() {
      if(this.codeType) {
        let _this = this
        await codeProvider.getList(this.codeType,this.condition || {}).then(resp => {
          let value = _.find(resp, function(o) { return o.value == _this.value; })
          _this.text = value['text']
        }).catch(err => {
          _g.toastMsg("error",err)
        })
      } else {
        console.error('codeType is not empty!');
      }
    }
  },
  watch : {
    value: {
      handler(newValue,oldValue) {
        this.initData();
      },
      deep: true
    },
    condition: {
      handler(newValue,oldValue) {
        this.initData();
      },
      deep: true
    },
  },
  created() {
    this.initData();
  },
  mounted() {
  }
}
</script>

<style scoped lang="scss">

</style>

